﻿// (c) Copyright 2013 Mike Riedel.
// This source is subject to the Microsoft Public License (Ms-PL).
// All other rights reserved.

using System;
using FreshMeat.ErrorHandlingBlock;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ErrorHandlingBlock.Tests
{
   [TestClass]
   public class FixedRetryPlanTest
   {
      [TestMethod]
      public void FixedLifecycle()
      {
         var plan = new FixedRetryPlan(6, TimeSpan.FromTicks(2));

         var attempt = 1;

         Assert.IsTrue(plan.ShouldRetry(attempt));
         Assert.AreEqual(2, plan.GetTimeUntilNextAttempt(attempt).Ticks);

         attempt = 2;

         Assert.IsTrue(plan.ShouldRetry(attempt));
         Assert.AreEqual(2, plan.GetTimeUntilNextAttempt(attempt).Ticks);

         attempt = 3;

         Assert.IsTrue(plan.ShouldRetry(attempt));
         Assert.AreEqual(2, plan.GetTimeUntilNextAttempt(attempt).Ticks);
         
         attempt = 4;

         Assert.IsTrue(plan.ShouldRetry(attempt));
         Assert.AreEqual(2, plan.GetTimeUntilNextAttempt(attempt).Ticks);
         
         attempt = 5;

         Assert.IsTrue(plan.ShouldRetry(attempt));
         Assert.AreEqual(2, plan.GetTimeUntilNextAttempt(attempt).Ticks);
         
         attempt = 6;

         Assert.IsFalse(plan.ShouldRetry(attempt));
         
         attempt = 7;

         Assert.IsFalse(plan.ShouldRetry(attempt));
      }
   }
}